<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <link rel="stylesheet" href="../static/js/prettify/prettify.css"/>
    <style>
        .demo{
            margin-bottom:20px;
            padding:20px;
            border-bottom:1px solid #1b926c;
        }
        /*input.ng-invalid {*/
            /*border: 3px solid red;*/
        /*}*/
        /*input.ng-valid {*/
            /*border: 3px solid green;*/
        /*}*/
        .error{
            color:red;
            font-weight: bold;
        }
        /*.navbar{*/
            /*border:1px solid #1b926c;*/
            /*background-color: #1fa67a;*/
        /*}*/

    </style>
</head>
<body>

 <div class="container">
     <div class="row">
         <nav class="navbar navbar-default navbar-static-top">
             <div class="container-fluid">
                 <div class="navbar-header">
                     <a class="navbar-brand" href="../index.html">首页</a>
                 </div>
                 <ul class="nav navbar-nav">
                    <li class="active"><a href="javascript:void(0)">Link</a></li>
                    <li><a href="javascript:void(0)">Link2</a></li>
                 </ul>
             </div>
         </nav>
     </div>
<div ng-app="myApp">
    <div class="row demo" ng-controller="FormController">
        <h3>Demo1: 表单验证</h3>
        <form name="signup_form" novalidate ng-submit="signupForm()">
            <fieldset>
                <legend>Signup</legend>
                <div class="form-group">
                    <label for="name">Your name</label>
                    <input type="text"
                           class="form-control"
                           id="name"
                           placeholder="Name"
                           name="name"
                           ng-model="signup.name"
                           ng-minlength="3"
                           ng-maxlength="20" required />
                    <div class="error"
                         ng-show="signup_form.name.$dirty && signup_form.name.$invalid">
                        <small class="error"
                               ng-show="signup_form.name.$error.required">
                            Your name is required.
                        </small>
                        <small class="error"
                               ng-show="signup_form.name.$error.minlength">
                            Your name is required to be at least 3 characters
                        </small>
                        <small class="error"
                               ng-show="signup_form.name.$error.maxlength">
                            Your name cannot be longer than 20 characters
                        </small>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-4">
                        <label for="email">Your Email</label>
                        <input type="email"
                               id="email"
                               class="form-control"
                               placeholder="Email"
                               name="email"
                               ng-model="signup.email"
                               ng-minlength="3"
                               ng-maxlength="20"
                               required />
                        <div class="error"
                             ng-show="signup_form.email.$dirty && signup_form.email.$invalid">
                            <small class="error"
                                   ng-show="signup_form.email.$error.required">
                                Your email is required.
                            </small>
                            <small class="error"
                                   ng-show="signup_form.email.$error.minlength">
                                Your email is required to be at least 3 characters
                            </small>
                            <small class="error"
                                   ng-show="signup_form.email.$error.email">
                                That is not a valid email. Please input a valid email.
                            </small>
                            <small class="error"
                                   ng-show="signup_form.email.$error.maxlength">
                                Your email cannot be longer than 20 characters
                            </small>
                        </div>
                    </div>

                    <div class="col-md-4">
                        <label for="username">Username</label>
                        <input type="text"
                               id="username"
                               class="form-control"
                               placeholder="Desired Username"
                               name="username"
                               ng-model="signup.username"
                               ng-minlength="3"
                               ng-maxlength="20"
                               required />
                        <div class="error"
                             ng-show="signup_form.username.$dirty && signup_form.username.$invalid">
                            <small class="error"
                                   ng-show="signup_form.username.$error.required">
                                Please input a username
                            </small>
                            <small class="error"
                                   ng-show="signup_form.username.$error.minlength">
                                Your username is required to be at least 3 characters
                            </small>
                            <small class="error"
                                   ng-show="signup_form.username.$error.maxlength">
                                Your username cannot be longer than 20 characters
                            </small>
                            <small class="error"
                                   ng-show="signup_form.username.$error.unique">
                                That username is taken, please try another
                            </small>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <button type="submit" style="margin-top: 25px;" ng-disabled="signup_form.$invalid" class="btn btn-default">Submit</button>
                    </div>
                </div>
            </fieldset>
        </form>

    </div>
</div>

 </div>
</body>
</html>
<script src="http://cdn.bootcss.com/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script src="../static/js/prettify/prettify.min.js"></script>
<script>
    /**
     * pretiffy美化代码
     */
    $(function() {
        $('pre').addClass('prettyprint linenums').attr('style', 'overflow:auto');
        window.prettyPrint && prettyPrint();
    });
</script>
<script>
    var myApp=angular.module("myApp",[]);
    myApp.controller("FormController",function($scope){
      $scope.signupForm=function(){
          $scope.invalid_submitted= false;
          $scope.signupForm = function() {
              if ($scope.signup_form.$valid) {
                  //正常提交
                  alert("通过验证，提交表单了");
              } else {
                  $scope.signup_form.invalid_submitted = true;
              }
          }
      };
    });
</script>
